home *** CD-ROM | disk | FTP | other *** search
/ Netware Super Library / Netware Super Library.iso / remote / jservr / genjob.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-15  |  9.9 KB  |  284 lines

  1. /***************************************************************************** 
  2.  * 
  3.  * Program Name:jsuper,jsubmit,jserver 
  4.  * 
  5.  * Filename:genjob.c 
  6.  * 
  7.  * Date Created:2/2/89 
  8.  * 
  9.  * Version:  1.0 
  10.  * 
  11.  * Programmers:Greg Peto 
  12.  * 
  13.  * Files used: 
  14.  * 
  15.  * Date Modified:  
  16.  * 
  17.  * Modifications:  
  18.  * 
  19.  * Comments:This file contains routines used by all the job server  
  20.  *             utilities. 
  21.  * 
  22.  ****************************************************************************/ 
  23.  
  24. /* functions in this file: 
  25.  GetArg() 
  26.  FindJobServer() 
  27.  CheckServerForQueue() 
  28. */ 
  29. #include"genjob.h" 
  30. #include<time.h> 
  31. #include<string.h> 
  32. #include<ctype.h> 
  33.  
  34. /* constants definitions */ 
  35. /* global variables and data types */ 
  36. char         *jobQueueName= JOB_QUEUE_NAME;/* name of job queue 
  37.                            bindery object */ 
  38. int          jobQueueType= OT_JOB_QUEUE;/* Object type to be used 
  39.                            when scanning bindery */ 
  40. BYTE         jobServerConID;/* server with target queue */ 
  41. long         jobQueueID;   /* bindery object ID of 
  42.                            job queue */ 
  43. /* module specific varables and data types */ 
  44. /* macro definitions */ 
  45.  
  46. /*****************************************************************************/ 
  47.  
  48. int ScanArg(arg,command_args,num_args,argString,argInt,argTime,argDate) 
  49.  /* Descrip: 
  50.      This function scans arg trying to parse off a known command. 
  51.      Assumes that arg should be a command line argument. 
  52.      Assumes that all legal integer, time or date arguments >= 0. 
  53.      It returns the command token value from command_args, if successful, 
  54.         along with arguments. 
  55.      It calls badUsage() if error detected, which does not return. 
  56.     Algorithm:// 
  57.  */ 
  58.  /* Input: */ 
  59.  char        *arg;         /* element of argv, assumes past '/' */ 
  60.  COMMAND_ARGScommand_args[];/* possible command line arguments */ 
  61.  int      num_args;   /* length of command_args[] */ 
  62.  
  63.  /* Output: */ 
  64.  char   *argString;/* command argument variable buffer */ 
  65.  long   *argInt;/* numeric argument variable */ 
  66.  JOB_TIME*argTime;/* hour (0-23):minute (0-59).second (0-59) format */ 
  67.  JOB_DATE*argDate;/* month (1-12)/day (1-31) /year (1900 + default) 
  68.                       format */ 
  69.   
  70. {    /* ScanArg // */ 
  71.  int i; 
  72.  BOOLEANhasEqual; 
  73.  char   argCom[MAX_COM_KEY];/* command keyword buffer */ 
  74.  char   errorBuffer[128]; 
  75.  /*--------------------------------------------------main body */ 
  76.  GetArg(arg,argCom,&hasEqual,argString,argInt,argTime,argDate); 
  77.  for (i = 0; i < num_args; ++i) 
  78.  { 
  79.    if (strlen(argCom) < command_args[i].num_sig) 
  80.      continue; /* not long enouph to check */ 
  81.    if (strncmp(argCom,command_args[i].com_key,strlen(argCom)) == 0) 
  82.    {   /* matched command keyword, verify args to command */ 
  83. #if 0/* may have optional parameters that are not required */ 
  84.      if ((command_args[i].req_string == FALSE AND 
  85.           command_args[i].req_int == FALSE) AND hasEqual) 
  86.         sprintf("Warning: command argument %s takes no parameters, parameters ignored.\n", 
  87.           command_args[i].com_key); 
  88.      else 
  89. #endif 
  90.      if ((command_args[i].req_string AND argString[0] == '\0') OR 
  91.                (command_args[i].req_int AND *argInt == -1)) 
  92.      { 
  93.         sprintf(errorBuffer,"Command line %s argument parameter incorrect", 
  94.           command_args[i].com_key); 
  95.         badUsage(errorBuffer); 
  96.      } 
  97.  
  98.      return(command_args[i].com_token);/* successful */ 
  99.    }   /* end of if strncmp() */ 
  100.  } 
  101.  badUsage("Unrecognized command line argument"); 
  102. }    /* end of ScanArg */ 
  103.   
  104. /********************************************************************/ 
  105.  
  106. void GetArg(arg,argCom,hasEqual,argString,argInt,argTime,argDate) 
  107.  /* Descrip: 
  108.      This function pulls the command line keyword, and comand line 
  109.         args out of argv and puts them in argCom, argString, and argInt. 
  110.      If argInt returned -1 integer parameter did not start with a digit. 
  111.      Both argCom and argString are mapped to upper case. 
  112.     Algorithm:// 
  113.  */ 
  114.  /* Input: */ 
  115.  char*arg;                 /* element of argv, assumes past '/' */ 
  116.  
  117.  /* Output: */ 
  118.  char   *argCom;/* command keyword buffer */ 
  119.  BOOLEAN*hasEqual;/* '=' character found in argument */ 
  120.  char   *argString;/* command argument variable buffer */ 
  121.  long   *argInt;/* numeric argument variable */ 
  122.  JOB_TIME*argTime;/* hour (0-23):minute (0-59).second (0-59) format */ 
  123.  JOB_DATE*argDate;/* month (1-12)/day (1-31) /year (1900 + default) 
  124.                       format */ 
  125. {    /* GetArg // */ 
  126.  int    cnt; 
  127.  time_t ltime;/* parameter to time() */ 
  128.  struct tm*ldate;/* struct needed for localtime() call */ 
  129.  char     *subptr;/* ptr to sub-string */ 
  130.  /*--------------------------------------------------main body */ 
  131.  argString[0]= '\0'; 
  132.  *argInt  = -1; 
  133.  memset(argTime,-1,sizeof(argTime)); 
  134.  memset(argDate,-1,sizeof(argDate)); 
  135.  
  136.  for (cnt = 0; 
  137.      *arg NOT= '=' AND *arg AND cnt < MAX_COM_KEY; 
  138.      ++arg,++argCom, ++cnt) 
  139.    *argCom= toupper(*arg); 
  140.  *argCom= '\0'; 
  141.  
  142.  if (*arg++ NOT= '=') 
  143.    *hasEqual= FALSE; 
  144.  else 
  145.  {  /* found '=', skip it and continue */ 
  146.    *hasEqual= TRUE; 
  147.    strcpy(argString,arg); 
  148.    strupr(argString); 
  149.    if (isdigit(*arg)) 
  150.    { 
  151.      *argInt = argTime->hour = argDate->month= atol(arg); 
  152.  
  153.      /* try to pull out time */ 
  154.      argTime->minute= 0; 
  155.      argTime->second= 0; 
  156.      if (subptr = strchr(arg,':')) 
  157.         if (isdigit(*(++subptr))) 
  158.         {   /* assume have minute */ 
  159.           argTime->minute= atoi(subptr); 
  160.           if (subptr = strchr(subptr,'.')) 
  161.              if (isdigit(*(++subptr))) 
  162.                /* assume have second */ 
  163.                argTime->second= atoi(subptr); 
  164.              else 
  165.                argTime->second= 0; 
  166.         } 
  167.  
  168.      /* try to pull out date */ 
  169.      time(<ime); 
  170.      ldate = localtime(<ime);/* get local time for defaults */ 
  171.      argDate->day= ldate->tm_mday; 
  172.      argDate->year= ldate->tm_year; 
  173.      if (subptr = strchr(arg,'/')) 
  174.         if (isdigit(*(++subptr))) 
  175.         {   /* assume have day */ 
  176.           argDate->day= atoi(subptr); 
  177.           if (subptr = strchr(subptr,'/')) 
  178.              if (isdigit(*(++subptr))) 
  179.                /* assume have year */ 
  180.                if ((argDate->year= atoi(subptr)) > 1900) 
  181.                  argDate->year-= 1900; 
  182.         } 
  183.    }   /* end of isdigit */ 
  184.  }   /* end of found '=' */ 
  185. }    /* end of GetArg */ 
  186.   
  187. /********************************************************************/ 
  188.  
  189. void FindJobServer(queueServerName,mustHaveQueue) 
  190.  /* Descrip: 
  191.      This function will attempt to find a connection that matches 
  192.         the specified server name, or the first one with a bindery 
  193.         object of the correct name. 
  194.      It will attempt to find the job queue on the server and put it 
  195.         its object ID in jobQueueID and it will try to put connection ID 
  196.         of the server in jobServerConID. 
  197.      Assumes queueServerName is a valid array, but if the 1st character 
  198.         is '\0' then it is ignored and all attached servers are searched 
  199.         for a valid job queue. 
  200.     Algorithm:// 
  201.  */ 
  202.  /* Input: */ 
  203. char queueServerName[];/* optional name of server to look for queue in */ 
  204. BOOLEANmustHaveQueue;/* abort program if queue not found */ 
  205.  
  206.  /* Output: */ 
  207.   
  208. {    /* FindJobServer // */ 
  209.  intccode; 
  210.  longCheckServerForQueue(); 
  211.  /*--------------------------------------------------main body */ 
  212.  jobServerConID= -1;/* set sentinel value so can tell if found */ 
  213.  if (queueServerName[0]) 
  214.  { 
  215.    if (ccode = GetConnectionID(queueServerName,&jobServerConID)) 
  216.      switch (ccode) 
  217.      { 
  218.         caseNOT_ATTACHED_TO_SERVER: 
  219.           /* ? Is this all I need to do to attach ? */ 
  220.           if (AttachToFileServer(queueServerName,&jobServerConID)) 
  221.           { 
  222.              printf("Could not attach to server %s\n",queueServerName); 
  223.              exit(1); 
  224.           } 
  225.           break; 
  226.         caseUNKNOWN_FILE_SERVER: 
  227.           printf("Cannot submit to unknown file server %s.\n", 
  228.              queueServerName); 
  229.           exit(1); 
  230.         caseSERVER_BINDERY_LOCKED: 
  231.           printf("Bindery for server %s locked, cannot submit.\n", 
  232.              queueServerName); 
  233.           exit(1); 
  234.         default: 
  235.           printf("Unable to get a connection to server %s\n", 
  236.              queueServerName); 
  237.      } 
  238.    if ((jobQueueID = CheckServerForQueue(jobServerConID)) == NULL AND mustHaveQueue) 
  239.    { 
  240.      printf("Job queue not found on server %s\n",queueServerName); 
  241.      exit(1); 
  242.    } 
  243.  } else 
  244.    for (jobServerConID = 1;jobServerConID <= MAX_SERVER_ATTACHES; ++jobServerConID) 
  245.      if (jobQueueID = CheckServerForQueue(jobServerConID)) 
  246.         break; 
  247. }    /* end of FindJobServer */ 
  248.   
  249. /********************************************************************/ 
  250.  
  251. long CheckServerForQueue(conID) 
  252.  /* Descrip: 
  253.      This function checks the server at given connection ID for a legal 
  254.         queue to recieve job.  If successfull, it returns the object ID 
  255.         of the queue in the bindery of the server. 
  256.     Algorithm:// 
  257.    BUGS: 
  258.      Currently no steps are taken to make sure the conID passed to 
  259.         SetPreferredConnectionID is defined.  It will work correctly 
  260.         as currently coded, but goes to the default server if conID 
  261.         not defined and this may not be desirable. 
  262.  */ 
  263.  /* Input: */ 
  264. WORDconID; 
  265.  /* Output: */ 
  266.   
  267. {    /* CheckServerForQueue // */ 
  268.  longobjectID; 
  269.  intccode; 
  270.  /*--------------------------------------------------main body */ 
  271.  if (IsconnectionIDInUse(conID) == FALSE) 
  272.    return(NULL); 
  273.  
  274.  objectID = -1; 
  275.  SetPreferredConnectionID(conID); 
  276.  ccode = GetBinderyObjectID(jobQueueName,OT_JOB_QUEUE,&objectID); 
  277.  if ( (ccode == 0) && (objectID != -1) ) 
  278.      return(objectID); 
  279.  else 
  280.    return(NULL); 
  281. }    /* end of CheckServerForQueue */ 
  282.   
  283. /********************************************************************/ 
  284.